#include "global.h"

Item::Item(QWidget *parent, QString avator, QString title,
           QString last_update, QString content)
{

    count = 0;

    add_attr("avator", avator);
    add_attr("title", title);
    add_attr("last_update", last_update);
    add_attr("content", content);

    get_label("avator")->setPixmap(QPixmap(get_attr("avator")).scaled(54, 54));
    get_label("avator")->setGeometry(0, 0, 54, 54);

    get_label("title")->setText(get_attr("title"));
    get_label("title")->setGeometry(70, 0, 200, 20);
    get_label("title")->setStyleSheet("color:blue;font-size: 20px;");

    get_label("last_update")->setText(get_attr("last_update"));
    get_label("last_update")->setGeometry(70, 20, 200, 14);
    get_label("last_update")->setStyleSheet("color: #9d9d9d");

    get_label("content")->setText(get_attr("content"));
    get_label("content")->setGeometry(0, 60, 300, 30);
    get_label("content")->setStyleSheet("font-size: 15px;");

};

void Item::add_attr(QString attr, QString data)
{
    names.insert(attr, data);
    labels.insert(attr, new QLabel(this));
}

QString Item::get_attr(QString attr)
{
    return names.find(attr).value();
}

QLabel* Item::get_label(QString attr)
{
    return labels.find(attr).value();
}

Item::~Item()
{
}


void Item::add_picture(QString w)
{
    int row, column;
    pictures.append(w);
    QLabel *l = new QLabel(this);
    labels.insert(QString("picture_%1").arg(count), l);
    l->setPixmap(QPixmap(w).scaled(100, 100));
    row = count / 3;
    column = count % 3;
    l->setGeometry(column * 100, 130 + row * 100, 100, 100);
    count++;
}
